<?php

class ZFDulcet_Form_Element extends Zend_Form_Element {

    public static function formatElementAsButton(Zend_Form_Element & $element) {
        ZFKiller_Form_Element::addAttrib($element, 'class', 'button right');
    }

    public static function formatElementAsCheckbox(Zend_Form_Element & $element) {
        ZFKiller_Form_Element::addAttrib($element, 'class', 'checkbox');

        if (null === ($formeeClass = $element->getAttrib('formeeclass'))) {
            $formeeClass = 'grid-12-12';
        }
        $formeeClass .= ' checkbox';

        $element
                ->removeDecorator('HtmlTag')
                ->removeDecorator('Description')
                ->addDecorator('Label', array('placement' => 'APPEND'))
                ->addDecorator('Description', array('tag' => 'p', 'class' => 'subtip'))
                ->addDecorator('HtmlTag', array(
                    'tag' => 'div',
                    'id' => 'element-' . $element->getId(),
                    'class' => $formeeClass,
                ))
        ;
    }

    public static function formatElementAsDate(Zend_Form_Element & $element) {
        self::formatElementAsText($element);
        ZFKiller_Form_Element::addAttrib($element, 'class', 'date');
    }

    public static function formatElementAsNumber(Zend_Form_Element & $element) {
        self::formatElementAsText($element);
        //ZFKiller_Form_Element::addAttrib($element, 'class', 'sizeauto');
    }

    public static function formatElementAsRadio(Zend_Form_Element & $element) {
        ZFKiller_Form_Element::addAttrib($element, 'class', 'radio');

        if (null === ($formeeClass = $element->getAttrib('formeeclass'))) {
            $formeeClass = 'grid-12-12';
        }

        $element
                ->removeDecorator('HtmlTag')
                ->removeDecorator('Label')
                ->removeDecorator('Description')
                ->removeDecorator('Errors')
                ->addDecorator('HtmlTagRadioOptions', array(
                    'tag' => 'ul',
                    'class' => 'formee-list',
                ))
                ->addDecorator('Label')
                ->addDecorator('Description', array('tag' => 'span', 'class' => 'subtip'))
                ->addDecorator('Errors')
                ->addDecorator('HtmlTag', array(
                    'tag' => 'div',
                    'id' => 'element-' . $element->getId(),
                    'class' => $formeeClass,
                ))
        ;
    }

    public static function formatElementAsText(Zend_Form_Element & $element) {
        ZFKiller_Form_Element::addAttrib($element, 'class', 'txt formee-txt');

        if (null === ($formeeclass = $element->getAttrib('formeeclass'))) {
            $formeeclass = 'grid-12-12';
        }
        $htmlTag1Class =  $formeeclass . ' ' . ((string) $element->getAttrib('htmltag1_class'));

        $clearAfter = $element->getAttrib('clearafter');

        $element
                ->setAttrib('formeeclass', NULL)
                ->setAttrib('clearafter', NULL)
                ->setAttrib('htmltag1_class', NULL)
                ->removeDecorator('HtmlTag')
                ->removeDecorator('Label')
                ->addDecorator('Description', array('tag' => 'span', 'class' => 'subtip'))
                ->addDecorator('Errors')
                ->addDecorator('Label')
                ->addDecorator(array('htmltag1' => 'HtmlTag'), array(
                    'tag' => 'div',
                    'id' => 'element-' . $element->getId(),
                    'class' => $htmlTag1Class,
                ))
        ;

        if ($clearAfter) {
            $element->addDecorator(array('htmltagclear' => 'HtmlTag'), array(
                'tag' => 'div',
                'class' => 'clear',
                'placement' => Zend_Form_Decorator_Abstract::APPEND,
            ));
        }
    }

    public static function formatElementAsTextarea(Zend_Form_Element & $element) {
        ZFKiller_Form_Element::addAttrib($element, 'class', 'txtarea');

        if (null === ($formeeClass = $element->getAttrib('formeeclass'))) {
            $formeeClass = 'grid-12-12';
        }

        $element
                ->removeDecorator('HtmlTag')
                ->removeDecorator('Label')
                ->addDecorator('Description', array('tag' => 'span', 'class' => 'subtip'))
                ->addDecorator('Errors')
                ->addDecorator('Label')
                ->addDecorator('HtmlTag', array(
                    'tag' => 'div',
                    'id' => 'element-' . $element->getId(),
                    'class' => $formeeClass,
                ))
        ;
    }

}
